<template>
    <div class="article-wrap" id="shouldfix">
        <detail :detail='article'></detail>
        <like :article='this.$route.params.artId'></like>
    </div>
</template>

<script>
    import {appService} from '../../service/appService'
    import {homeService} from '../../service/homeService'
    import detail from '../../component/detail/detail.vue'
    import like from '../../component/common/like.vue'

    export default {
        components: {'detail':detail,'like':like},
        // 添加以下代码
        metaInfo () {
            // console.log(this);
            const title = this.shareData.title || this.article.title
            return {
                title,
                meta: [
                    { vmid: 'description', name: 'description', content: this.shareData.desc  || '点击查看详情' },
                    { vmid: 'keyWords', name: 'keyWords', content: '运联首页' },
                ]
            }
        },
        data () {
            return {
                count:1,params:{sortKey:''}
            }
        },
        asyncData({store,route}) {
            function getArticle(){
                homeService.getArticle(route.params.artId).then(function(res){
                    if(!res.data) return
                    store.state.homeStore.article = res.data
                    // console.log(store.state.homeStore.article);
                })
            }
            function getshare() {
                let params = {
                    type:10,typeId:route.params.artId
                }
                return appService.getshare(params).then(function(res){
                    // console.log(res.data.datas);
                    store.state.shareData=res.data.datas
                })
            }
            return Promise.all([
               getArticle(),getshare()
            ])

        },
        computed: {
            //将存在store中的数据取出
            article:{
                // getter
                get: function () { return this.$store.state.homeStore.article || []},
                // setter
                set: function (newValue) {return newValue}
            },
            shareData:{
                // getter
                get: function () { return this.$store.state.shareData || []},
                // setter
                set: function (newValue) {return newValue}
            },
        },
        mounted: function() {
            let that = this
            that.getArticle()
            // console.log(that.article);
            let share = {
                hasGet:true,
                title:that.shareData.title || that.article.title,
                imageUrl: that.shareData.imgUrl,
                brief: that.shareData.desc || '点击查看详情',
                url: that.shareData.dataUrl || window.location.href
            }
            let params = {
                type:10,typeId:that.$route.params.artId
            }
            appService.getWxJssdk().then(function () {
                appService.getWxShare(params,'文章详情')
            })
        },
        methods: {
            //获取列表
            getArticle:function () {
                let that = this
                let store = that.$store
                let route = that.$route
                homeService.getArticle(route.params.artId).then(function(res){
                    if(!res.data) return
                    store.state.homeStore.article = res.data
                })
            },
        }
    }
</script>

<style lang="less">
    @import url("../../assets/css/mescroll.min.css");
    .article-wrap{
        background:#fff;
        padding-bottom:60px;
        .nav-filter{
            position: fixed;
            width: 100%;
            z-index:99;
        }
        .list-out{
            padding-top:1.4rem;
        }
    }

</style>
